﻿var tidyup = null;
﻿var tidyupflag = false;
var maxzidx = 0;
window.setStatus = function(stat){
	switch(stat) {
		case 'initialized':
			with($id('loading')) {
				firstChild.innerHTML = "正在传输数据,请稍候...";
				style.display = "block";
			}
			break;
		case 'loading':
			$id('loading').firstChild.innerHTML += ".";
			break;
		case 'loaded':
			$id('loading').firstChild.innerHTML = "传输完成,正在进行处理...";
			break;
		case 'done':
			$id('loading').style.display = "none";
			break;
		default:
			window.status = stat;
			$id('loading').style.display = "none";
			break;
	}
	return true
}
function queue(win) {
	var zidx = win.style.zIndex;
	var wins = win.parentNode.childNodes;
	for(var i = 0;i < wins.length;i++) {
		if(wins[i].ready && wins[i].style.zIndex > zidx) {
			wins[i].style.zIndex -= 1;
		}
	}
	win.style.zIndex = maxzidx;
}
function openWindow(wid) {
	var win = $(wid);
	win.style.display = 'block';
	if(!win.ready) {
		win.ready = true;
		win.onmousedown = function() {
			queue(win);
		}
		$(win.firstChild).bindDragTo(win);
		with(win) {
			style.zIndex = ++maxzidx;
			style.top = Math.max(document.documentElement.scrollTop + document.documentElement.offsetHeight / 2 - clientHeight / 2,0) + "px";
			style.left = Math.max(document.documentElement.scrollLeft + document.documentElement.offsetWidth / 2 - clientWidth / 2,0) + "px";
			eval(getAttribute("onstart"));
		}
	}
	queue(win);
}
function closeWindow(wid) {
	$(wid).style.display = 'none';
	return event.returnValue = !(event.cancelBubble = true);
}
function loadHomeSet() {
	tidyupflag = false;
	var f = $("homeset");
	if(tidyup != null) {
		f.reset();
		with(tidyup.documentElement) {
			f.elements['title'].value = selectSingleNode("head/title").text;
			f.elements['keywords'].value = selectSingleNode("head/meta[@name='keywords']").getAttribute("content");
			f.elements['description'].value = selectSingleNode("head/meta[@name='description']").getAttribute("content");
			
			with(selectSingleNode("body")) {
				f.elements['topbanner'].value = selectSingleNode("p[@id='topbanner']").text;
				f.elements['middlebanner'].value = selectSingleNode("p[@id='middlebanner']").text;
				
				var nodes = selectNodes("p[@id='focus']/a");
				with(f.elements['focustitle'][0].parentNode.parentNode.parentNode.parentNode){innerHTML = innerHTML}
				for(var i = 0;i < nodes.length;i++) {
					with(nodes[i]) {
						f.elements['focustitle'][i].value = text;
						f.elements['focusurl'][i].value = getAttribute("href");
						f.elements['focusimg'][i].value = getAttribute("name");
					}
				}
				nodes = selectNodes("p[@id='subject']/a");
				with(f.elements['subjecttitle'][0].parentNode.parentNode.parentNode.parentNode){innerHTML = innerHTML}
				for(var i = 0;i < nodes.length;i++) {
					with(nodes[i]) {
						f.elements['subjecttitle'][i].value = getAttribute("name");
						f.elements['subjecturl'][i].value = getAttribute("href");
						f.elements['subjectsummary'][i].value = text;
					}
				}
				nodes = selectNodes("p[@id='recommend']/a");
				with(f.elements['recommendtitle'][0].parentNode.parentNode.parentNode.parentNode){innerHTML = innerHTML}
				for(var i = 0;i < nodes.length;i++) {
					with(nodes[i]) {
						f.elements['recommendtitle'][i].value = text;
						f.elements['recommendurl'][i].value = getAttribute("href");
						f.elements['recommendname'][i].value = getAttribute("name");
						f.elements['recommendauthor'][i].value = getAttribute("id");
					}
				}
				nodes = selectNodes("p[@id='picked']/a");
				with(f.elements['pickedtitle'][0].parentNode.parentNode.parentNode.parentNode){innerHTML = innerHTML}
				for(var i = 0;i < nodes.length;i++) {
					with(nodes[i]) {
						f.elements['pickedtitle'][i].value = text;
						f.elements['pickedurl'][i].value = getAttribute("href");
						f.elements['pickedname'][i].value = getAttribute("name");
						f.elements['pickedauthor'][i].value = getAttribute("id");
					}
				}
				nodes = selectNodes("p[@id='copartner']/a");
				var copartnerlist = $id("copartnerlist");
				copartnerlist.innerHTML = copartnerlist.firstChild.outerHTML;
				for(var i = 0;i < nodes.length;i++) {
					var copartner = copartnerlist.lastChild.cloneNode(true);
					copartnerlist.appendChild(copartner);
					copartner.innerHTML = copartner.innerHTML;
					with(nodes[i]) {
						f.elements['copartnertitle'][i].value = text;
						f.elements['copartnerurl'][i].value = getAttribute("href");
						f.elements['copartnerlogo'][i].value = getAttribute("name");
					}
				}
				nodes = selectNodes("p[@id='friendlink']/a");
				var friendlinklist = $id("friendlinklist");
				friendlinklist.innerHTML = friendlinklist.firstChild.outerHTML;
				for(var i = 0;i < nodes.length;i++) {
					var copartner = friendlinklist.lastChild.cloneNode(true);
					friendlinklist.appendChild(copartner);
					copartner.innerHTML = copartner.innerHTML;
					with(nodes[i]) {
						f.elements['friendlinktitle'][i].value = getAttribute("name");
						f.elements['friendlinkurl'][i].value = getAttribute("href");
						f.elements['friendlinksummary'][i].value = text;
					}
				}
			}
		}
	} else {
		var xmlhttp = new HTTPRequest(true,false,false);
		xmlhttp.send("tidyup.xml",null,function(r) {
			tidyup = r.getXML();
			loadHomeSet();
		});
		var focusindex = 0;
		ScriptLoader.Load("/js/uploader.js", function() {
			var uploader = new FileUploader($id('focusuploader'), "/", 453, false);
			uploader.onUploadBefore = function(f) {
				if(f.elements[0].value.length > 1) {
					var re = new RegExp(".(jpg|jpeg|gif|png|bmp)\\s*$","i");
					if(!(new RegExp(".(jpg|jpeg|gif|png|bmp)\\s*$","i")).test(f.elements[0].value)) {
						alert('图片格式无效，可接受的图片格式包括JPEG、GIF、PNG和BMP');
						return false;
					}
					var t = f.ownerDocument.createElement("input");
					t.name = "focus";
					focusindex = t.value = $("focusindex").current || 0;
					f.appendChild(t);
					return true;
				}
				return false;
			}
			uploader.onUploadCompleted = function(filename) {
				tidyupflag = true;
				f.elements["focusimg"][focusindex].value = filename;
			}
			uploader.initialize();
			uploader.container.style.width = "462px";
		});
	}
}
function login(r) {
	$id("loading").style.display = "none";
	var t = r.getText();
	if(t.length > 0) {
		$id("loginbox").style.display = "none";
		$id("tipbar").style.display = "block";
		var btns = $id("account").getElementsByTagName("li");
		if(t != 1) {
			btns[1].style.display = "none";
		} else {
			btns[1].style.display = "block";
		}
		$id("loginform").reset();
	} else {
		$id("loginbox").style.display = "block";
		$id("crc_img").src = "/CRCImage.aspx?mod=manage&" + (new Date()).getTime()
	}
}
function logout() {
	var xmlhttp = new HTTPRequest(true,true,false);
	xmlhttp.send("adminlogin.aspx",null,function(r) {
		location.replace("/");
	});
}
function switchPanel(ul) {
	var e = event.srcElement;
	while(e != ul && e.tagName != "LI") {
		e = e.parentNode;
	}
	if(e.tagName == "LI" && e.className != "current") {
		var childs = ul.childNodes;
		var panels = ul.parentNode.nextSibling.childNodes;
		var i = 0;
		for(;i < childs.length;i++) {
			if(childs[i] == e) {
				break;
			}
		}
		childs[ul.current = (ul.current||0)].className = "";
		panels[ul.current].className = "tabpanel";
		childs[ul.current = i].className = "current";
		panels[ul.current].className = "tabpanel current";
		eval(e.getAttribute("onstart"));
	}
}
function saveHomeSet() {
	var f = $("homeset");
	var clone = tidyup.cloneNode(true);
	with(tidyup.documentElement) {
		selectSingleNode("head/title").text = f.elements['title'].value;
		selectSingleNode("head/meta[@name='keywords']").setAttribute("content", f.elements['keywords'].value);
		selectSingleNode("head/meta[@name='description']").setAttribute("content", f.elements['description'].value);
		
		with(selectSingleNode("body")) {
			selectSingleNode("p[@id='topbanner']").text = f.elements['topbanner'].value;
			selectSingleNode("p[@id='middlebanner']").text = f.elements['middlebanner'].value;
			
			with(selectSingleNode("p[@id='focus']")) {
				text = "";
				for(var i = 0;i < f.elements['focustitle'].length;i++) {
					if(f.elements['focustitle'][i].value.trim().length > 0 && f.elements['focusurl'][i].value.trim().length > 0 && f.elements['focusimg'][i].value.trim().length > 0) {
						var fcs = tidyup.createElement("a");
						fcs.setAttribute("href", f.elements['focusurl'][i].value.trim());
						fcs.setAttribute("name", f.elements['focusimg'][i].value.trim());
						fcs.text = f.elements['focustitle'][i].value.trim();
						appendChild(fcs);
					}
				}
			}
			with(selectSingleNode("p[@id='subject']")) {
				text = "";
				for(var i = 0;i < f.elements['subjecttitle'].length;i++) {
					if(f.elements['subjecttitle'][i].value.trim().length > 0 && f.elements['subjecturl'][i].value.trim().length > 0 && f.elements['subjectsummary'][i].value.trim().length > 0) {
						var subject = tidyup.createElement("a");
						subject.setAttribute("href", f.elements['subjecturl'][i].value.trim());
						subject.setAttribute("name", f.elements['subjecttitle'][i].value.trim());
						subject.text = f.elements['subjectsummary'][i].value.trim();
						appendChild(subject);
					}
				}
			}
			with(selectSingleNode("p[@id='recommend']")) {
				text = "";
				for(var i = 0;i < f.elements['recommendtitle'].length;i++) {
					if(f.elements['recommendtitle'][i].value.trim().length > 0 && f.elements['recommendurl'][i].value.trim().length > 0 && f.elements['recommendname'][i].value.trim().length > 0) {
						var recommend = tidyup.createElement("a");
						recommend.setAttribute("href", f.elements['recommendurl'][i].value.trim());
						recommend.setAttribute("name", f.elements['recommendname'][i].value.trim());
						recommend.setAttribute("id", f.elements['recommendauthor'][i].value.trim());
						recommend.text = f.elements['recommendtitle'][i].value.trim();
						appendChild(recommend);
					}
				}
			}
			with(selectSingleNode("p[@id='picked']")) {
				text = "";
				for(var i = 0;i < f.elements['pickedtitle'].length;i++) {
					if(f.elements['pickedtitle'][i].value.trim().length > 0 && f.elements['pickedurl'][i].value.trim().length > 0 && f.elements['pickedname'][i].value.trim().length > 0) {
						var picked = tidyup.createElement("a");
						picked.setAttribute("href", f.elements['pickedurl'][i].value.trim());
						picked.setAttribute("name", f.elements['pickedname'][i].value.trim());
						picked.setAttribute("id", f.elements['pickedauthor'][i].value.trim());
						picked.text = f.elements['pickedtitle'][i].value.trim();
						appendChild(picked);
					}
				}
			}
			with(selectSingleNode("p[@id='copartner']")) {
				text = "";
				for(var i = 0;i < (f.elements['copartnertitle'].length || 1);i++) {
					if((f.elements['copartnerlogo'][i]||f.elements['copartnerlogo']).value.trim().length > 0 && (f.elements['copartnerurl'][i]||f.elements['copartnerurl']).value.trim().length > 0) {
						var copartner = tidyup.createElement("a");
						copartner.setAttribute("href", (f.elements['copartnerurl'][i]||f.elements['copartnerurl']).value.trim());
						copartner.setAttribute("name", (f.elements['copartnerlogo'][i]||f.elements['copartnerlogo']).value.trim());
						copartner.text = (f.elements['copartnertitle'][i]||f.elements['copartnertitle']).value.trim();
						appendChild(copartner);
					}
				}
			}
			with(selectSingleNode("p[@id='friendlink']")) {
				text = "";
				for(var i = 0;i < (f.elements['friendlinktitle'].length || 1);i++) {
					if((f.elements['friendlinktitle'][i]||f.elements['friendlinktitle']).value.trim().length > 0 && (f.elements['friendlinkurl'][i]||f.elements['friendlinkurl']).value.trim().length > 0) {
						var friendlink = tidyup.createElement("a");
						friendlink.setAttribute("href", (f.elements['friendlinkurl'][i]||f.elements['friendlinkurl']).value.trim());
						friendlink.setAttribute("name", (f.elements['friendlinktitle'][i]||f.elements['friendlinktitle']).value.trim());
						friendlink.text = (f.elements['friendlinksummary'][i]||f.elements['friendlinksummary']).value.trim();
						appendChild(friendlink);
					}
				}
			}
		}
	}
	var xmlhttp = new HTTPRequest();
	xmlhttp.send("HomeUpdate.aspx", tidyup, "alert('保存成功')", function() {tidyup=clone});
}
function checkLastRow(box) {
	var row = box.parentNode.parentNode;
	if(!row.nextSibling) {
		var boxs = row.getElementsByTagName("input");
		for(var i = 0;i < boxs.length;i++) {
			if(boxs[i].value.trim().length > 0) {
				var newrow = row.cloneNode(true);
				row.parentNode.appendChild(newrow);
				boxs = newrow.getElementsByTagName("input");
				for(var j = 0;j < boxs.length;j++) {
					boxs[j].value = "";
				}
				newrow.innerHTML = newrow.innerHTML;
				return;
			}
		}
	}
}
function moveTabItem(child, n) {
	var item = child.parentNode;
	var where = "";
	var titem = null;
	if(n < 0 && (!!(titem = item.previousSibling) && (where = "afterEnd")) || n > 0 && (!!(titem = item.nextSibling) && (where = "beforeBegin"))) {
		tidyupflag = true;
		var ul = item.parentNode.previousSibling.getElementsByTagName("ul")[0];
		item.insertAdjacentElement(where, titem);
		ul.childNodes[ul.current=(ul.current||0)].insertAdjacentElement(where, ul.childNodes[ul.current += n]);
	}
}
function adminUpdate(f, isDelete) {
	if(isDelete) {
		f.elements["npws"].disabled = f.elements["repeatpwd"].disabled = true;
	}
	$(f).post(function(r) {
		if(eval(r.getText()) > 0) {
			f.reset();
			alert("操作成功");
		} else {
			alert("操作过程发生未知错误");
		}
	});
	f.elements["npws"].disabled = f.elements["repeatpwd"].disabled = false;
}
function selectRow(t) {
	with(event.srcElement) {
		if(tagName == "TH") {
			parentNode.className = (parentNode.className != "selected" ? "selected":"");
			if(parentNode.parentNode.tagName == "THEAD") {
				var rows = t.tBodies[0].rows;
				for(var i = 0; i < rows.length;i++) {
					rows[i].className = parentNode.className;
				}
			}
		}
	}
}
TopicList = {
	titleFilter: "&size=15",
	currentPage: 1,
	maxPage: 1,
	regex: /^([^\/]+)\/.*\/(\d+)/i,
	load: function(p, rest) {
		this.currentPage = p;
		if(rest) {
			this.titleFilter = "&size=15&title=" + escape($id("topictitlefilter").value);
		}
		var xmlhttp = new HTTPRequest();
		xmlhttp.send("DataReader.aspx?ds=admintopiclist", "page=" + p + this.titleFilter, function(r) {
			var de = r.getXML().documentElement;
			var topicList = $id("topicList");
			var tr = topicList.tHead.rows[0];
			tr.className = "";
			with(topicList.tBodies[0]) {
				while(rows.length > 0) {
					removeChild(rows[0]);
				}
				var topics = de.firstChild.childNodes;
				for(var i = 0;i < topics.length;i++) {
					var author = topics[i].selectSingleNode("account").text;
					var row = tr.cloneNode(true);
					appendChild(row);
					var t = document.createElement("a");
					t.href = author + "/topic/" + topics[i].selectSingleNode("id").text;
					t.onclick = function() {
						TopicList.read(this);
						return event.returnValue = !(event.cancelBubble = true);
					}
					t.innerText = topics[i].selectSingleNode("title").text;
					row.cells[1].innerHTML = '<div class="topictitle"></div>';
					row.cells[1].firstChild.appendChild(t);
					
					var a = document.createElement("a");
					a.href = author;
					a.target = "_blank";
					a.innerText = topics[i].selectSingleNode("nickname").text;
					row.cells[2].innerHTML = '<div class="topicauthor"></div>';
					row.cells[2].firstChild.appendChild(a);
					
					row.cells[3].innerHTML = topics[i].selectSingleNode("postdate").text.substr(0,17);
				}
			}
			var size = eval(de.getAttribute("size"));
			var count = eval(de.lastChild.text);
	
			this.maxPage = Math.ceil(count / size);
			
			var start = Math.max(Math.min(this.maxPage - 9, p - 5), 1);
			var end = Math.min(start + 10,this.maxPage);
			var pager = [];
			if(start > 1) {
				pager.push('<a href="#" onclick="TopicList.load(1)" title="第一页">|&lt;</a>');
				pager.push('<a href="#" onclick="TopicList.load(' + (start - 1) + ')">..</a>');
			}
			for(;start <= end;start++) {
				if(start != p) {
					pager.push('<a href="#" onclick="TopicList.load(' + start + ')">[' + start + ']</a>');
				} else {
					pager.push('<span>[' + start + ']</span>');
				}
			}
			if(this.maxPage > end) {
				pager.push('<a href="#" onclick="TopicList.load(' + (end + 1) + ')">..</a>');
				pager.push('<a href="#" onclick="TopicList.load(' + this.maxPage + ')" title="最后页">&gt;|</a>');
			}
			$id('topicpager').innerHTML = pager.join('');
		}.bind(this));
	},
	deleteTopics: function() {
		this.getSelected();
		if(this.selecteds.length > 0) {
			var ids = [], authors = [];
			with($id("topicList").tBodies[0]) {
				for(var i = 0;i < this.selecteds.length;i++) {
					rows[this.selecteds[i]].cells[1].firstChild.firstChild.getAttribute("href").replace(this.regex, function(m,$1,$2) {
						authors.push($1);
						ids.push($2);
					});
				}
			}
			openWindow("topicdeleter");
			var f = $("topicdeleterform");
			f.reset();
			f.elements["ids"].value = ids;
			f.elements["authors"].value = authors;
		}
	},
	deleteDone: function() {
		if(this.currentPage < this.maxPage) {
			this.load(this.currentPage);
		}
		else if(this.currentPage > 1 && this.selecteds.length == $id("topicList").tBodies[0].rows.length) {
			this.load(this.currentPage - 1);
		} else {
			with($id("topicList").tBodies[0]) {
				while(this.selecteds.length > 0) {
					removeChild(rows[this.selecteds.pop()]);
				}
			}
		}
		$id("topicList").tHead.rows[0].className = "";
		$id('topicdeleter').style.display='none';
	},
	addToTidyup: function(nodeName, lim) {
		this.getSelected();
		if(this.selecteds.length > 0) {
			if(tidyupflag && confirm("您之前对首页设置的修改尚未保存，如果不保存将会丢失之前的修改，现在保存吗？")) {
				saveHomeSet();
			}
			if(tidyup != null) {
				this.appendTidyup(nodeName, lim)
			} else {
				var xmlhttp = new HTTPRequest(true,true,false);
				xmlhttp.send("tidyup.xml",null,function(r) {
					tidyup = r.getXML();
					this.appendTidyup(nodeName, lim)
				}.bind(this));
			}
		}
	},
	appendTidyup: function(nodeName, lim) {
		var xmlhttp = new HTTPRequest();
		var clone = tidyup.cloneNode(true);
		var node = tidyup.documentElement.selectSingleNode("body/p[@id='" + nodeName + "']");
		with($id("topicList").tBodies[0]) {
			for(var i = 0;i < this.selecteds.length;i++) {
				var ele = tidyup.createElement("a");
				var row = rows[this.selecteds[i]];
				ele.text = row.cells[1].innerText;
				ele.setAttribute("name", row.cells[2].innerText);
				ele.setAttribute("href", row.cells[1].firstChild.firstChild.getAttribute("href"));
				ele.setAttribute("id", row.cells[2].firstChild.firstChild.getAttribute("href"));
				node.appendChild(ele);
			}
		}
		var nodes = node.selectNodes("a");
		if(nodes.length > lim) {
			for(var i = 0;i < nodes.length - lim;i++) {
				nodes[i].parentNode.removeChild(nodes[i]);
			}
		}
		var xmlhttp = new HTTPRequest();
		xmlhttp.send("HomeUpdate.aspx", tidyup, null, function() {tidyup=clone});
		loadHomeSet();
	},
	getSelected: function() {
		this.selecteds = [];
		var topics = $id("topicList").tBodies[0].rows;
		for(var i = 0;i < topics.length;i++) {
			if(topics[i].className == "selected") {
				this.selecteds.push(i);
			}
		}
	},
	read: function(topic) {
		openWindow("topicview");
		$id("topicviewtitle").innerText = topic.innerText;
		$id("topicsummary").innerHTML = $id("topiccontent").innerHTML = "";
		var xmlhttp = new HTTPRequest(true,false,false);
		xmlhttp.send(topic.href, null, function(r) {
			var de = r.getXML().documentElement;
			var summary = de.selectSingleNode("head/meta[@name='description']");
			if(summary != null) {
				$id("topicsummary").innerHTML = summary.getAttribute("content");
			} else {
				$id("topicsummary").innerHTML = "";
			}
			$id("topiccontent").innerHTML = de.selectSingleNode("body").text;
		});
	}
}
UserList = {
	currentPage:1,
	maxPage:1,
	state:0,
	filter:"&size=50",
	selecteds:[],
	load: function(state, p, rest) {
		this.currentPage = p;
		if(rest) {
			this.filter = "&size=50&account=" + escape($id("accountfilter").value) + "&nickname=" + escape($id("nicknamefilter").value);
		}
		var xmlhttp = new HTTPRequest();
		xmlhttp.send("DataReader.aspx?ds=userlist", "state=" + (this.state = state) + "&page=" + p + this.filter, function(r) {
			var de = r.getXML().documentElement;
			var userList = $id("userList");
			var tr = userList.tHead.rows[0];
			tr.className = "";
			with(userList.tBodies[0]) {
				while(rows.length > 0) {
					removeChild(rows[0]);
				}
				var users = de.firstChild.childNodes;
				for(var i = 0;i < users.length;i++) {
					var row = tr.cloneNode(true);
					appendChild(row);
					row.userid = users[i].selectSingleNode("id").text;
					row.cells[1].innerHTML = '';
					var a = document.createElement("a");
					a.target = "_blank";
					a.href = a.innerText = users[i].selectSingleNode("account").text;
					row.cells[1].appendChild(a);
					
					row.cells[2].innerHTML = '';
					var em = document.createElement("a");
					em.target = "_blank";
					em.href = "mailto:" + users[i].selectSingleNode("email").text;
					em.innerText = users[i].selectSingleNode("nickname").text;
					row.cells[2].appendChild(em);
					
					row.cells[3].innerHTML = users[i].selectSingleNode("registertime").text.substr(0,17);
					row.cells[4].innerHTML = users[i].selectSingleNode("logintime").text.substr(0,17);
					
					if(1 != eval(users[i].selectSingleNode("state").text)) {
						row.cells[0].className = "locked";
					}
				}
			}
			var size = eval(de.getAttribute("size"));
			var count = eval(de.lastChild.text);
	
			this.maxPage = Math.ceil(count / size);
			
			var start = Math.max(Math.min(this.maxPage - 9, p - 5), 1);
			var end = Math.min(start + 10,this.maxPage);
			var pager = [];
			if(start > 1) {
				pager.push('<a href="#" onclick="UserList.load(UserList.state,1)" title="第一页">|&lt;</a>');
				pager.push('<a href="#" onclick="UserList.load(UserList.state,' + (start - 1) + ')">..</a>');
			}
			for(;start <= end;start++) {
				if(start != p) {
					pager.push('<a href="#" onclick="UserList.load(UserList.state,' + start + ')">[' + start + ']</a>');
				} else {
					pager.push('<span>[' + start + ']</span>');
				}
			}
			if(this.maxPage > end) {
				pager.push('<a href="#" onclick="UserList.load(UserList.state,' + (end + 1) + ')">..</a>');
				pager.push('<a href="#" onclick="UserList.load(UserList.state,' + this.maxPage + ')" title="最后页">&gt;|</a>');
			}
			$id('userpager').innerHTML = pager.join('');
		}.bind(this));
	},
	setStatus: function() {
		var users = this.getSelectedUsers();
		if(users.length > 0) {
			var xmlhttp = new HTTPRequest();
			xmlhttp.send("SimpleUpdate.aspx", "ds=usersupdate&users=" + users, function(r) {
				if(eval(r.getText()) > 0) {
					if(this.state != 0) {
						this.updateDone();
					}
					else {
						with($id("userList").tBodies[0]) {
							while(this.selecteds.length > 0) {
								with(rows[this.selecteds.pop()]) {
									className = "";
									cells[0].className = cells[0].className == "locked" ? "" : "locked";
								}
							}
						}
					}
				}
			}.bind(this));
		}
	},
	deleteUsers: function() {
		if(($("userdeleterform").elements["users"].value = this.getSelectedUsers()).length > 0) {
			openWindow("userdeleter");
		}
	},
	updateDone: function() {
		if(this.currentPage < this.maxPage) {
			this.load(this.state,this.currentPage);
		}
		else if(this.currentPage > 1 && this.selecteds.length == $id("userList").tBodies[0].rows.length) {
			this.load(this.state,this.currentPage - 1);
		} else {
			with($id("userList").tBodies[0]) {
				while(this.selecteds.length > 0) {
					removeChild(rows[this.selecteds.pop()]);
				}
			}
		}
		$id("userList").tHead.rows[0].className = "";
		$("userdeleter").style.display = "none";
	},
	sendMessage: function() {
		$("messagerform").elements["users"].value = this.getSelectedUsers();
		openWindow("messager");
	},
	sendDone: function(r) {
		alert("已向" + r.getText() + "个用户发送了信息");
		$id("messager").style.display = "none";
	},
	getSelected: function() {
		this.selecteds = [];
		var users = $id("userList").tBodies[0].rows;
		for(var i = 0;i < users.length;i++) {
			if(users[i].className == "selected") {
				this.selecteds.push(i);
			}
		}
	},
	getSelectedUsers:function() {
		this.getSelected();
		var users = [];
		with($id("userList").tBodies[0]) {
			for(var i = 0;i < this.selecteds.length;i++) {
				users.push(rows[this.selecteds[i]].userid);
			}
		}
		return users;
	}
}
function switchMessageTarget(ul) {
	with(event.srcElement) {
		if(tagName == "LI") {
			className = "checked";
			if(($id("messagerform").elements["area"].value = getAttribute("value")) == 0) {
				nextSibling.className = "";
			} else {
				previousSibling.className = "";
			}
		}
	}
}
window.onload = function() {
	var xmlhttp = new HTTPRequest(true,true,false);
	xmlhttp.send("checkadminlogin.aspx",null,login);
}